package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.TestPaper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.ManyToOne;

/**
 * @author beingven
 * @Description TODO
 * @createTime 2021年01月06日 15:54:00
 */
public interface TestPaperRepository extends JpaRepository<TestPaper, Integer>, JpaSpecificationExecutor {

    //通过id查询试卷信息
    @Query(value = "select tp from TestPaper tp where tp.id = ?1")
    TestPaper findPaperById(Integer id);

    //根据id更新下载量
    @Query(value = "update TestPaper tp set tp.downloadNumber = ?2 where tp.id = ?1")
    @Transactional
    @Modifying
    void updateDownloadNumber(Integer id, Long downLoadNumber);
}
